//
//  XJCommunityIdentityListVC.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/7/16.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJCommunityIdentityListVC.h"
#import "XJCmtIdentityVC.h" //跳转社区认证 VC

#import "XJCmtIdentityListModel.h"
#import "XJCmtIdentityListCell.h"

@interface XJCommunityIdentityListVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation XJCommunityIdentityListVC

#pragma mark - 一 lazy
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        
        NSString *clsName = NSStringFromClass([XJCmtIdentityListCell class]);
        
        [_tableView registerNib:[UINib nibWithNibName:clsName bundle:nil] forCellReuseIdentifier:clsName];
        
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}
- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark - 二 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"社区认证列表";
    self.tableView.frame = self.view.bounds;
    [self.view addSubview:self.tableView];
    
    self.dataArray = [self modelArrayFromDicArr:self.identity_infoArr];
}

// dic -- > model
- (NSMutableArray *)modelArrayFromDicArr:(NSArray *)dicArr {
    NSMutableArray *newArr = [NSMutableArray array];
    for (NSDictionary *tempDic in dicArr) {
        
        XJCmtIdentityListModel *model = [XJCmtIdentityListModel mj_objectWithKeyValues:tempDic];
        
        [newArr addObject:model];
    }
    
    return newArr;
}

#pragma mark - 三 UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *clsName = NSStringFromClass([XJCmtIdentityListCell class]);
    
    XJCmtIdentityListCell *cell = [tableView dequeueReusableCellWithIdentifier:clsName];
    
    XJCmtIdentityListModel *model = self.dataArray[indexPath.row];
    cell.model = model;
    return cell;
}

#pragma mark - 四 UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    XJCmtIdentityListModel *selModel = self.dataArray[indexPath.row];
    
    XJCmtIdentityVC *cmtidVC = [XJCmtIdentityVC new];
    cmtidVC.communityId = [NSString stringWithFormat:@"%@",selModel.cmtId];
    
    [self.navigationController pushViewController:cmtidVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
